#ifndef VSqlDataMRef_H
#define VSqlDataMRef_H

#include "VSqlQuery.h"

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

class VSqlDataMRef
{
private:
	QSqlField m_idRec;
	QSqlField m_refIdItem;
	QSqlField m_refIdRec;
	QSqlField m_pos;

public:
	VSqlDataMRef()
		:m_idRec		("idRec",QVariant::Int)
		,m_refIdItem("refIdItem",QVariant::Int)
		,m_refIdRec	("refIdRec",QVariant::Int)
		,m_pos			("pos",QVariant::Int)
	{}

	void setIdRec(const QVariant &v) { m_idRec.setValue(v);}
	QSqlField idRec() const { return m_idRec;}
	QSqlField *idRecPtr() { return &m_idRec;}

	void setRefIdItem(const QVariant &v) { m_refIdItem.setValue(v);}
	QSqlField refIdItem() const { return m_refIdItem;}
	QSqlField *refIdItemPtr() { return &m_refIdItem;}

	void setRefIdRec(const QVariant &v) { m_refIdRec.setValue(v);}
	QSqlField refIdRec() const { return m_refIdRec;}
	QSqlField *refIdRecPtr() { return &m_refIdRec;}

	void setPos(const QVariant &v) { m_pos.setValue(v);}
	QSqlField pos() const { return m_pos;}
	QSqlField *posPtr() { return &m_pos;}

	VSqlFieldList fieldList() const
	{
		return VSqlFieldList()
			<< m_idRec
			<< m_refIdItem
			<< m_refIdRec
			<< m_pos;
	}

	VSqlFieldPtrList fieldPtrList()
	{
		return VSqlFieldPtrList()
			<< &m_idRec
			<< &m_refIdItem
			<< &m_refIdRec
			<< &m_pos;
	}

	static QString tableName(const QString &dataTableName) { return dataTableName + "_mRef";}
	static void createTable(const QSqlDatabase &db,const QString &dataTableName);

	static void deleteRef
	(
		const QSqlDatabase &db,
		const QString &dataTableName,
		const QVariantList &idRecList
	);
	
	static void deleteRef
	(
		const QSqlDatabase &db,
		const QString &dataTableName,
		const QVariant &idRec,
		const QVariant &refIdItem
	);
	
	static void insertRef
	(
		const QSqlDatabase &db,
		const QString &dataTableName,
		const QVariant &idRec,
		const QVariant &refIdItem,
		const QVariant &refIdRec
	);
};

///////////////////////////////////////////////////////////////////////////////

#endif
